package com.javaGame.util;

import com.javaGame.GameMap;
import com.javaGame.role.*;
import com.javaGame.role.enemy.Boss;
import com.javaGame.role.enemy.Light;
import com.javaGame.role.enemy.RedEnemy;
import com.javaGame.role.enemyBullet.StarBullet;

import javax.swing.*;
import java.awt.*;

/**
 * 图片初始化类
 */
public class ImageInit {

    public static void init(JFrame jf){
        //创建媒体追踪器对象
        MediaTracker track = new MediaTracker(jf);
        //在媒体追踪器中加入图片，分成1组
        track.addImage(GameMap.mapImg,1);
        //将图片切割成图片数组，第一个参数为图片路径，第二个参数为分割份数，
        //第三个参数为媒体追踪器，第四个参数为分组
        Boss.bossImg = CutImage.cutOneImage(
                "image/boss/playSpear.png",18,track,1);
        //切割女孩图片
        Girl.forwardNotHitImg = CutImage.cutOneImage(
                "image/girl/forward.png",4,track,1);
        Girl.forwardImg = new Image[]{Girl.forwardNotHitImg[0],
                        Girl.forwardNotHitImg[2]};
        Girl.backNotHitImg = CutImage.cutOneImage(
                "image/girl/back.png",4,track,1);
        Girl.backImg = new Image[]{Girl.backNotHitImg[0],
                Girl.backNotHitImg[2]};
        Girl.eddyImg = CutImage.cutOneImage(
                "image/girl/circumgyrate.png",12,track,1);
        Girl.dieImg = CutImage.getSingleImage("image/girl/die.png",track,1);
        //女孩子弹
        GirlBullet.girlBulletImg = CutImage.getSingleImage(
                "image/jbullet/dart.png",track,1);
        //红色怪物
        RedEnemy.redEnemyImg = CutImage.cutOneImage(
                "image/enemy/redEnemy.png",3,track,1);
        //灯怪
        Light.lightImg = CutImage.cutOneImage(
                "image/enemy/lightEnemy.png",2,track,1);
        //爆炸
        Bomb.bombImg = CutImage.cutOneImage(
                "image/bomb/detonate.png",5,track,1);
        //道具
        Prop.propImg  = CutImage.cutOneImage(
                "image/prop.png",3,track,1);
        //击中效果
        ByHitBom.byHitImg = CutImage.cutOneImage(
                "image/bomb/blast.png",4,track,1);
        //花瓣
        Flower.flowerImg = CutImage.cutOneImage("image/rose.png",4,track,1);
        //星形子弹
        StarBullet.starBulletImg = CutImage.cutOneImage(
                "image/enemyBullet/star.png",3,track,1);
        //菱形飞镖
        RhombicBullet.rhombicImg = CutImage.cutOneImage(
                "image/jbullet/rhombic.png",3,track,1 );
        //宠物貂
        Mink.normalImg = CutImage.cutOneImage("image/mink/normal.png",2,track,1);
        Mink.readyFireImg = CutImage.cutOneImage("image/mink/readyFire.png",6,track,1);
        Mink.fireImg = CutImage.cutOneImage("image/mink/fire.png",8,track,1);
        //火
        Fire.fireImg = CutImage.cutOneImage("image/fireImg.png",6,track,1);
        try {
            //1组中所有图片，全部加载完毕再显示
            track.waitForID(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
